home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / xshp15.zip / INITBALL.C < prev    next >
Text File  |  1992-01-05  |  4KB  |  106 lines

  1. /* Initializes the balls and adds them to the object list. */
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include "polygon.h"
  5.  
  6. #define NUM_BALLS 1              /* # of balls to initialize */
  7.  
  8. #include "balvert0.inc" /* face and vertex definitions for ball */
  9.  
  10. /* X, Y, Z rotations for balls, in tenths of degrees (angles) */
  11. static RotateControl InitialRotate[NUM_BALLS] = {
  12.    {0,90,0},};
  13. static MoveControl InitialMove[NUM_BALLS] = {
  14.    {0,0,35,0,0,-6000,0,0,-350}, };
  15. /* Face colors for various balls */
  16. static int Colors[NUM_BALLS][NUM_FACES] = {
  17.    {15,14,13,12,11,10,9,8,7,6,5,4,
  18.     14,13,12,11,10,9,8,7,6,5,4,15,
  19.     13,12,11,10,9,8,7,6,5,4,15,14,
  20.     12,11,10,9,8,7,6,5,4,15,14,13,
  21.     11,10,9,8,7,6,5,4,15,14,13,12,
  22.     10,9,8,7,6,5,4,15,14,13,12,11,},
  23. };
  24. /* Starting coordinates for balls in world space */
  25. static int BallStartCoords[NUM_BALLS][3] = {
  26.    {30,0,-6000},
  27. };
  28. /* Delay counts (speed control) for balls */
  29. static int InitRDelayCounts[NUM_BALLS] = {1};
  30. static int BaseRDelayCounts[NUM_BALLS] = {1};
  31. static int InitMDelayCounts[NUM_BALLS] = {1};
  32. static int BaseMDelayCounts[NUM_BALLS] = {1};
  33.  
  34. void InitializeBalls()
  35. {
  36.    int i, j, k;
  37.    PObject *WorkingBall;
  38.  
  39.    for (i=0; i<NUM_BALLS; i++) {
  40.       if ((WorkingBall = malloc(sizeof(PObject))) == NULL) {
  41.          printf("Couldn't get memory\n"); exit(1); }
  42.       WorkingBall->DrawFunc = DrawPObject;
  43.       WorkingBall->RecalcFunc = XformAndProjectPObject;
  44.       WorkingBall->MoveFunc = RotateAndMovePObject;
  45.       WorkingBall->RecalcXform = 1;
  46.       for (k=0; k<2; k++) {
  47.          WorkingBall->EraseRect[k].Left =
  48.             WorkingBall->EraseRect[k].Top = 0x7FFF;
  49.          WorkingBall->EraseRect[k].Right = 0;
  50.          WorkingBall->EraseRect[k].Bottom = 0;
  51.       }
  52.       WorkingBall->RDelayCount = InitRDelayCounts[i];
  53.       WorkingBall->RDelayCountBase = BaseRDelayCounts[i];
  54.       WorkingBall->MDelayCount = InitMDelayCounts[i];
  55.       WorkingBall->MDelayCountBase = BaseMDelayCounts[i];
  56.       /* Set the object->world xform to none */
  57.       for (j=0; j<3; j++)
  58.          for (k=0; k<4; k++)
  59.             WorkingBall->XformToWorld[j][k] = INT_TO_FIXED(0);
  60.       WorkingBall->XformToWorld[0][0] = 
  61.          WorkingBall->XformToWorld[1][1] =
  62.          WorkingBall->XformToWorld[2][2] = INT_TO_FIXED(1);
  63.       /* Set the initial location */
  64.       for (j=0; j<3; j++) {
  65.           WorkingBall->XformToWorld[j][3] =
  66.                 INT_TO_FIXED(BallStartCoords[i][j]);
  67.       }
  68.       /* Initial center coordinates */
  69.       WorkingBall->CenterInView.X = WorkingBall->XformToWorld[0][3];
  70.       WorkingBall->CenterInView.Y = WorkingBall->XformToWorld[1][3];
  71.       WorkingBall->CenterInView.Z = WorkingBall->XformToWorld[2][3];
  72.       WorkingBall->NumVerts = NUM_VERTS;
  73.       WorkingBall->VertexList = Verts;
  74.       WorkingBall->NumFaces = NUM_FACES;
  75.       WorkingBall->Rotate = InitialRotate[i];
  76.       WorkingBall->Move.MoveX = INT_TO_FIXED(InitialMove[i].MoveX);
  77.       WorkingBall->Move.MoveY = INT_TO_FIXED(InitialMove[i].MoveY);
  78.       WorkingBall->Move.MoveZ = INT_TO_FIXED(InitialMove[i].MoveZ);
  79.       WorkingBall->Move.MinX = INT_TO_FIXED(InitialMove[i].MinX);
  80.       WorkingBall->Move.MinY = INT_TO_FIXED(InitialMove[i].MinY);
  81.       WorkingBall->Move.MinZ = INT_TO_FIXED(InitialMove[i].MinZ);
  82.       WorkingBall->Move.MaxX = INT_TO_FIXED(InitialMove[i].MaxX);
  83.       WorkingBall->Move.MaxY = INT_TO_FIXED(InitialMove[i].MaxY);
  84.       WorkingBall->Move.MaxZ = INT_TO_FIXED(InitialMove[i].MaxZ);
  85.       if ((WorkingBall->XformedVertexList =
  86.             malloc(NUM_VERTS*sizeof(Point3))) == NULL) {
  87.          printf("Couldn't get memory\n"); exit(1); }
  88.       if ((WorkingBall->ProjectedVertexList =
  89.             malloc(NUM_VERTS*sizeof(Point3))) == NULL) {
  90.          printf("Couldn't get memory\n"); exit(1); }
  91.       if ((WorkingBall->ScreenVertexList =
  92.             malloc(NUM_VERTS*sizeof(Point))) == NULL) {
  93.          printf("Couldn't get memory\n"); exit(1); }
  94.       if ((WorkingBall->FaceList =
  95.             malloc(NUM_FACES*sizeof(Face))) == NULL) {
  96.          printf("Couldn't get memory\n"); exit(1); }
  97.       /* Initialize the faces */
  98.       for (j=0; j<NUM_FACES; j++) {
  99.          WorkingBall->FaceList[j].VertNums = VertNumList[j];
  100.          WorkingBall->FaceList[j].NumVerts = VertsInFace[j];
  101.          WorkingBall->FaceList[j].Color = Colors[i][j];
  102.       }
  103.       AddObject((Object *)WorkingBall);
  104.    }
  105. }
  106.